set rC = (the right of sprite sC - the left of sprite sC)/2
set rSNum to (the right of sprite sNum - the left of sprite sNum)/2
set cH to the locH of sprite sC + 1
set cV to the locV of sprite sC + 1
set rC to rC - rSNum
set deltaH to the locH of the clickLoc - the locH of sprite sNum
set deltaV to the locV of the clickLoc - the locV of sprite sNum
repeat while the mouseDown
if the mouseH < cH then
set mH to the mouseH - deltaH
set mV to the mouseV - deltaV
set A to mH - cH
set B to mV - cV
set r to sqrt(A*A + B*B)
if A <> 0 then
set grad = float(B)/A
set constraint = 2.2 -- tan of 130 degrees swing
if grad <= constraint and grad >= 0 - constraint then
set angle = atan (grad) + atan (constraint)
displayYear angle / (atan(constraint)*2) -- return percentage of travel
set newX = rC/sqrt(1+grad*grad)
if mH < cH then set newX to 0 - newX
set newY to Grad*newX
set the locH of sprite sNum to newX + cH
set the locV of sprite sNum to newY + cV
end if
end if
updateStage
end if
end repeat
end
on displayYear percentVal
global yearList
set yearList to [1066,1097,1215,1254,1265,1295,1341,1376,1523,1547,1605,1640,1678,1688,1694,1707,1716,1801,1803,1812,1832,1834,1852,1867,1911,1918,1941,1958,1978,1992]
set yearNum to integer(count(yearList) * percentval)
if yearNum = 0 then set yearNum =1
set the text of field "readout" to string(getAt(yearList, yearNum))